package com.company.project.web;
import com.company.project.api.IGoodsApi;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.TradeGoods;
import com.company.project.service.TradeGoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2018/12/07.
*/
public  abstract class TradeGoodsController implements IGoodsApi {
    @Resource
    public TradeGoodsService tradeGoodsService;
    @ApiIgnore
    @PostMapping("/add")
    public Result add(TradeGoods tradeGoods) {
        tradeGoodsService.save(tradeGoods);
        return ResultGenerator.genSuccessResult();
    }
    @ApiIgnore
    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        tradeGoodsService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }
    @ApiIgnore
    @PostMapping("/update")
    public Result update(TradeGoods tradeGoods) {
        tradeGoodsService.update(tradeGoods);
        return ResultGenerator.genSuccessResult();
    }
    @ApiIgnore
    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        TradeGoods tradeGoods = tradeGoodsService.findById(id);
        return ResultGenerator.genSuccessResult(tradeGoods);
    }
    @ApiIgnore
    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<TradeGoods> list = tradeGoodsService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
